package com.atguigu;

import com.alibaba.ververica.cdc.connectors.mysql.MySQLSource;
import com.alibaba.ververica.cdc.debezium.StringDebeziumDeserializationSchema;
import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.source.SourceFunction;

/**
 * @Author lizhenchao@atguigu.cn
 * @Date 2021/2/5 8:41
 */
public class FlinkSqlCDC {
    public static void main(String[] args) {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);

        SourceFunction<String> sourceFunction = MySQLSource.<String>builder()
            .hostname("hadoop162")
            .port(3306)
            .databaseList("gmall2021_realtime") // monitor all tables under inventory database
            .username("root")
            .password("aaaaaa")
            .deserializer(new StringDebeziumDeserializationSchema()) // converts SourceRecord to String
            .build();

        env
            .addSource(sourceFunction).setParallelism(1)
            .map(new MapFunction<String, String>() {
                @Override
                public String map(String value) throws Exception {
                    return value;
                }
            })
            .print();

        try {
            env.execute();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
